package qc.module.ehs.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.ehs.dto.epibolyperson.EpibolyPersonDto;
import qc.module.ehs.service.EhsEpibolyPersonService;

import java.util.List;

/**
 * EpibolyPersonController
 * @author YRR
 * @create 2025-03-13 21:30
 */
@RestController
@RequestMapping("/epibolyperson")
public class EpibolyPersonController {

    @Autowired
    private EhsEpibolyPersonService service;

    /**
     * 获取指定单位的相关人员信息
     * @param id 指定的单位id
     * @return List<EpibolyPersonDto>
     */
    @RequestMapping(value = "/unit", method = {RequestMethod.GET, RequestMethod.POST})
    public List<EpibolyPersonDto> getUnitByParam(@RequestParam(value = "id", required = true) String id) throws QCPromptException {
        return service.getByUnit(id);
    }

    /**
     * 获取指定单位的相关人员信息
     * @param id 指定的单位id
     * @return List<EpibolyPersonDto>
     * @throws QCPromptException
     */
    @RequestMapping(value = "/unit/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public List<EpibolyPersonDto> getUnitByPath(@PathVariable(value = "id", required = true) String id) throws QCPromptException {
        return service.getByUnit(id);
    }

    /**
     * 新增相关单位人员的信息
     * @param dto 相关人员的信息
     * @return null为成功，失败返回提示信息
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST, RequestMethod.PUT})
    public String add(@RequestBody EpibolyPersonDto dto) {
        return service.add(dto);
    }

    /**
     * 修改相关人员信息
     * @param dto 相关人员的信息
     * @return null为成功，失败返回提示信息
     */
    @RequestMapping(value = "/update", method = {RequestMethod.POST, RequestMethod.PUT})
    public String update(@RequestBody EpibolyPersonDto dto) {
        return service.update(dto);
    }

    /**
     * 修改指定相关人员的状态，设置为黑名单
     * @param id 指定的相关单位id
     * @return 成功返回null, 失败返回错误或提示信息
     */
    @RequestMapping(value = "/blacklist", method = {RequestMethod.POST, RequestMethod.PUT})
    public String addToBlackListByParam(@RequestParam(value = "id", required = true) String id) {
        return service.addToBlackList(id);
    }

    /**
     * 修改指定相关人员的状态，设置为黑名单
     * @param id 指定的相关单位id
     * @return 成功返回null, 失败返回错误或提示信息
     */
    @RequestMapping(value = "/blacklist/{id}", method = {RequestMethod.POST, RequestMethod.PUT})
    public String addToBlackListByPath(@PathVariable(value = "id", required = true) String id) {
        return service.addToBlackList(id);
    }

    /**
     * 删除指定相关人员
     * @param id 指定的相关单位id
     * @return 成功返回null, 失败返回错误或提示信息
     */
    @DeleteMapping("/delete")
    public String deleteByParam(@RequestParam(value = "id", required = true) String id) {
        return service.delete(id);
    }

    /**
     * 删除指定相关人员
     * @param id 指定的相关单位id
     * @return 成功返回null, 失败返回错误或提示信息
     */
    @DeleteMapping("/delete/{id}")
    public String deleteByPath(@PathVariable(value = "id", required = true) String id) {
        return service.delete(id);
    }

}
